package com.example.testnews.fragmant;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.testnews.R;
import com.example.testnews.adapter.CollectAdapter;
import com.example.testnews.adapter.HomeAdapter;
import com.example.testnews.bean.News;

import java.util.ArrayList;
import java.util.List;

public class CollectFragment extends Fragment {
    private static final String TAG = "CollectFragment";
    private RecyclerView mRecyclerView;
    private View mView;
    public static List<News> mCollectNewsList = new ArrayList<>();
    CollectAdapter collectAdapter = new CollectAdapter(getContext());

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        Log.i(TAG, "onViewCreated: ");
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser)
            collectAdapter.setCollectNews(HomeAdapter.collectNewsList);
    }


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView =inflater.inflate(R.layout.fragment_collect, container, false);
        collectAdapter = new CollectAdapter(getActivity());
        initCollectView();
//       CollectAdapter.setOnCollectItemClickListener(new CollectAdapter.OnCollectItemClickListener() {
//           @Override
//           public void onClick(int position) {
//               //Toast.makeText(getActivity(),"click" + position,Toast.LENGTH_SHORT).show();
//               String data = "News Detail Is Showing";
//               Intent intent = new Intent(getContext(), NewsActivity.class);
//               intent.putExtra("extra_data",data);
//               startActivity(intent);
//           }
//       });
        Log.i("Collect", "gsgsfgsgsdgs");
        return mView;

    }

    private void initCollectView() {
        mRecyclerView = mView.findViewById(R.id.collect_recyclerview);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        mRecyclerView.setAdapter(collectAdapter);

    }



    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
}
